﻿using System;

namespace ORM_Micro.Helpers
{
    public static class TypeExtensions
    {
        public static object ConvertFrom(this Type destType, object value)
        {
            var t = Nullable.GetUnderlyingType(destType) ?? destType;
            return (value == null) ? null : (t == typeof(Guid) ? new Guid(value.ToString()) : Convert.ChangeType(value, t));
        }

        public static object GetDefaultValue(this Type type)
        {
            return type.IsValueType ? Activator.CreateInstance(type) : null;
        } 
    }
}